<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for ASN1 Encoder Class 'asn1x509.js'</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// ======= TEST ===============================================================

// _test/z4.tsa.cer
var z4TSACERT = (function() {/*
-----BEGIN CERTIFICATE-----
MIIDETCCAfmgAwIBAgIBTTANBgkqh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----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

// root-r6
var PUBKEYRSA1 = (function() {/*
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAlQfoc8pm+ewUyns89w0I
8bRFCyyCtEjG61s8roO4QZIzFKRvf+kqzMawiGvFtonRxrL/FM5RFCHsSt0bWsbW
h+5NOhUG7WRmC5KAykTec5RO86eJf094YwjIElBtQmYvTbl5KE1SGooagLcZgQ5+
xIq8ZEwhHENo1z08isWyZtWQmrcxBsW+4m0yBqYe+bnrqqO4v76CY1DQ8BiJ3+QP
efXqoh8q0nAue+e8k7ttU+JIfIwQBzj/ZrJ3YX7g6ow8qrSk9vOVShIHbf2MsonP
0KBhd8hYdLDUIzr3XTrKotudCd5dRC2Q8YHNV5L6frxQBGM032uTGL5rNrI55Kwk
Nrfw77YcE1eTtt6y+OKFt3OiuDWqRfLgnTahb1SK8XJWbi6IxVFCRBWU7qPFOJab
Tk5aC0fzBjZJdzC8cTflpuwhCHX85mEWP3fV2ZGXhAps1AJNdMAU7f05+4PyXhSh
BLAL6f7uj+FuC7IIs2FmCWqxBjplllnA8DX9ydoojRoRh3CBCqiadR2eOoYFAJ7b
gNYl+dwFnidZTHY5W+r5paHYgw/R/98wEfmFzzNI9cptZBQselhP00sIScWVZBpj
Dnk99bOMylitnEJFeW4OhxlcVLFltr+Mm9wT6Q1vuC7cZ27JixG1hBSKABlwg3mR
l5HUGie/Nx4yB9gUYzwoTK8CAwEAAQ==
-----END PUBLIC KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

// aaa3.sbj.cer.pem
var CERTEE1 = (function() {/*
-----BEGIN CERTIFICATE-----
MIICqjCCAhOgAwIBAgIBBzANBgkqhkiG9w0BAQsFADAbMQswCQYDVQQGEwJVUzEM
MAoGA1UECgwDQ0ExMB4XDTIwMDUyNzEwMDgxOFoXDTMwMDUyNjEwMDgxOFowGzEL
MAkGA1UEBhMCVVMxDDAKBgNV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ODf1LkHs4JBd0w65wa2juu5XgxsEW34h
P1NIIUL6oeQwNEEj1c5Vg2XPSlIrb4/L8bEfaNT1vRktGp9exiRGLnrS55EoSitz
VjoQQV+ndcj/a1XR+iYYCCRMv4NErs+0wBYhXPIuyRfLuECdOQvG2QDITi6Lan7U
HlTjAoGAInfGmkb2jNkPGuNiZ+mU0+ZrOgLza/fLL9ErZ35jUPhGFzdGxJNobklv
sNoTd+E2GAU41YkJh24bncMLvJVYxHHA5iF7FBWx1SvpEyKVhhnIcuXGD7N5PbNZ
zEdmr9C6I7cPVkWO+sUV7zfFukexIcANmsd/oBBGKRoYzP5Tti4=
-----END RSA PRIVATE KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

// 0cert_rsa/z4.pub.p8.pem
var Z4PUBPEM = (function() {/*
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA33TqqLR3eeUmDtHS89qF
3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWbOiMAfDcDzlOxA
04DDnEFGAf+kDQiNSe2ZtqC7bnIc8+KSG/qOGQIVaay4Ucr6ovDkykO5Hxn7OU7s
Jp9TP9H0JH8zMQA6YzijYH9LsupTerrY3U6zyihVEDXXOv08vBHk50BMFJbE9iwF
wnxCsU5+UZUZYw87Uu0n4LPFS9BT8tUIvAfnRXIEWCha3KbFWmdZQZlyrFw0buUE
f0YN3/Q0auBkdbDR/ES2PbgKTJdkjc/rEeM0TxvOUf7HuUNOhrtAVEN1D5uuxE1W
SwIDAQAB
-----END PUBLIC KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];



// === BEGIN Other ASN1 structure class  ======================================

test("AlgorithmIdentifier class test", function() {
var _AlgId = KJUR.asn1.x509.AlgorithmIdentifier;
equal(new _AlgId({'name':'SHA1withRSA'}).getEncodedHex(),
      "300d06092a864886f70d0101050500",
      "constructor name SHA1withRSA");
equal(new _AlgId({'name':'SHA256withRSA'}).getEncodedHex(),
      "300d06092a864886f70d01010b0500",
      "constructor name SHA256withRSA");
equal(new _AlgId({'name':'SHA256withRSA', paramempty: true}).getEncodedHex(),
      "300b06092a864886f70d01010b",
      "constructor name SHA256withRSA, paramempty");
equal(new _AlgId({'name':'SHA1withDSA'}).getEncodedHex(),
      "300906072a8648ce380403",
      "constructor name SHA1withDSA");
equal(new _AlgId({'name':'SHA512withECDSA'}).getEncodedHex(),
      "300a06082a8648ce3d040304",
      "constructor name SHA512withECDSA");
equal(new _AlgId({'name':'rsaEncryption'}).getEncodedHex(),
        "300d06092a864886f70d0101010500",
	"constructor name rsaEncryption");
equal(new _AlgId({'name':'sha1'}).getEncodedHex(),
        "300906052b0e03021a0500",
	"constructor name sha1");

equal(new _AlgId({'name':'SHAwithRSAandMGF1'}).getEncodedHex(),
        "300d06092a864886f70d01010a3000",
	"constructor name SHAwithRSAandMGF1");

equal(new _AlgId({'name':'SHA256withRSAandMGF1'}).getEncodedHex(),
        "303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",
	"constructor name SHA256withRSAandMGF1");

equal(new _AlgId({'name':'SHA384withRSAandMGF1'}).getEncodedHex(),
        "303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",
	"constructor name SHA384withRSAandMGF1");

equal(new _AlgId({'name':'SHA512withRSAandMGF1'}).getEncodedHex(),
        "303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140",
	"constructor name SHA512withRSAandMGF1");
});

test("AlgorithmIdentifier SHA1withECDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA1withECDSA', paramempty: true});
equal(o.getEncodedHex(), "300906072a8648ce3d0401", "aaa");
});

test("AlgorithmIdentifier SHA256withECDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA256withECDSA', paramempty: true});
equal(o.getEncodedHex(), "300a06082a8648ce3d040302", "aaa");
});

test("AlgorithmIdentifier SHA1withDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA1withDSA', paramempty: true});
equal(o.getEncodedHex(), "300906072a8648ce380403", "aaa");
});

test("AlgorithmIdentifier SHA256withDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA256withDSA', paramempty: true});
equal(o.getEncodedHex(), "300b0609608648016503040302", "aaa");
});

// ===== BEGIN Name related class test ==============

test("GeneralNames class test", function() {
  var o = new KJUR.asn1.x509.GeneralNames([{'uri':'http://aaa.com/'}]);
  equal(o.getEncodedHex(), "3011860f687474703a2f2f6161612e636f6d2f", "constructor uri http://aaa.com/");

  var o = new KJUR.asn1.x509.GeneralNames([{uri:'http://aaa.com/'}, {dn: {certsubject: CERTEE1}}]);
  equal(o.getEncodedHex(), "3030860f687474703a2f2f6161612e636f6d2fa41d301b310b3009060355040613025553310c300a060355040a0c03454531", "constructor uri http://aaa.com/, dn certsubject EE out=" + o.getEncodedHex());
});

test("GeneralName class test", function() {
  var o;
  o = new KJUR.asn1.x509.GeneralName({'rfc822':'u1@foo.com'});
  equal(o.getEncodedHex(), "810a753140666f6f2e636f6d", "constructor rfc822 u1@foo.com");

  o = new KJUR.asn1.x509.GeneralName({'dns':'foo.com'});
  equal(o.getEncodedHex(), "8207666f6f2e636f6d", "constructor dns foo.com");

  o = new KJUR.asn1.x509.GeneralName({'uri':'http://aaa.com/'});
  equal(o.getEncodedHex(), "860f687474703a2f2f6161612e636f6d2f", "constructor uri http://aaa.com/");

  o = new KJUR.asn1.x509.GeneralName({certissuer: z4TSACERT});
  equal(o.getEncodedHex(), "a41d301b310b3009060355040613025553310c300a060355040a0c03434131", "constructor certissuer cert1");

  o = new KJUR.asn1.x509.GeneralName({certsubj: z4TSACERT});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b06035504030c0454534131", "constructor certsubj cert1");

  o = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b060355040a0c0454657374", "dn /C=US/O=Test out=" + o.getEncodedHex());

  o = new KJUR.asn1.x509.GeneralName({dn: {str: '/C=US/O=Test'}});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b060355040a0c0454657374", "dn str /C=US/O=Test");

  o = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'}});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b060355040a0c0454657374", "dn ldapstr O=Test,C=US");

  o = new KJUR.asn1.x509.GeneralName({dn: {certsubject: CERTEE1}});
  equal(o.getEncodedHex(), "a41d301b310b3009060355040613025553310c300a060355040a0c03454531", "dn certsubject=EE1 out=" + o.getEncodedHex());

  o = new KJUR.asn1.x509.GeneralName({dn: {certissuer: CERTEE1}});
  equal(o.getEncodedHex(), "a41d301b310b3009060355040613025553310c300a060355040a0c03434131", "dn certissuer=CA1 out=" + o.getEncodedHex());

  o = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b060355040a0c0454657374", "ldapdn O=Test,C=US");

  o = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'});
  equal(o.getEncodedHex(), "8704c0a80101", "ip: 192.168.1.1");

  o = new KJUR.asn1.x509.GeneralName({ip: '2001:db8::4'});
  equal(o.getEncodedHex(), "871020010db8000000000000000000000004", "ip: 2001:db8::4");

  o = new KJUR.asn1.x509.GeneralName({ip: '2606:4700:4700::1111'});
  equal(o.getEncodedHex(), "871026064700470000000000000000001111", "ip: 2606:4700:4700::1111");

  o = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'});
  equal(o.getEncodedHex(), "8704c0a80101", "ip: c0a80101");
});

// == X500Name class test 

test("X500Name class test", function() {
var _X500Name = KJUR.asn1.x509.X500Name;
var o = null;

equal((new _X500Name({array: [
[{type:"C",value:"US",ds:"prn"}],
[{type:"O",value:"aaa",ds:"utf8"}]
]})).getEncodedHex(),
"301b310b3009060355040613025553310c300a060355040a0c03616161",
"(1) new {array:[[C,US,prn][O,aaa,utf8]]}");

equal((new _X500Name({array: [
[{type:"C",value:"US",ds:"prn"}],
[{type:"O",value:"aaa",ds:"utf8"}]
],
str: "/C=JP/O=bbb"})).getEncodedHex(),
"301b310b3009060355040613025553310c300a060355040a0c03616161",
"(2) new {array:[[C,US,prn][O,aaa,utf8]]} str=/JP/bbb ignored");

o = new KJUR.asn1.x509.X500Name();
o.setByString("/C=US/O=aaa");
equal(o.getEncodedHex(), 
"301b310b3009060355040613025553310c300a060355040a0c03616161",
"setByString(/C=US/O=aaa)");

o = new KJUR.asn1.x509.X500Name();
o.setByString("/C=US/O=あ");
equal(o.getEncodedHex(), 
"301b310b3009060355040613025553310c300a060355040a0c03e38182",
"setByString(/C=US/O=あ)");

o = new KJUR.asn1.x509.X500Name();
o.setByObject({C: "US", O: "aaa"});
equal(o.getEncodedHex(), 
"301b310b3009060355040613025553310c300a060355040a0c03616161",
"setByObject({C: 'US', O: 'aaa'})");

o = new KJUR.asn1.x509.X500Name({'str':'/C=US/O=aaa'});
equal(o.getEncodedHex(),
"301b310b3009060355040613025553310c300a060355040a0c03616161",
"constructor str /C=US/O=aaa");

o = new KJUR.asn1.x509.X500Name({'C': 'US', 'O': 'aaa'});
equal(o.getEncodedHex(),
"301b310b3009060355040613025553310c300a060355040a0c03616161",
"constructor obj C:US, O:aaa");

o = new KJUR.asn1.x509.X500Name({'C': 'US', 'O': 'aa/'});
equal(o.getEncodedHex(),
"301b310b3009060355040613025553310c300a060355040a0c0361612f",
"constructor obj C:US, O:aa/");

o = new KJUR.asn1.x509.X500Name({'str': '/O=a/O=b/b/O=c/c/c'});
equal(o.getEncodedHex(),
"302a310a3008060355040a0c0161310c300a060355040a0c03622f62310e300c060355040a0c05632f632f63",
"constructor str /O=a/O=b/b/O=c/c/c");

o = new KJUR.asn1.x509.X500Name({str:'/O=a/O=b',rule:'prn'});
equal(o.getEncodedHex(),
"3018310a3008060355040a130161310a3008060355040a130162",
"constructor /O=a/O=b rule=prn");

o = new KJUR.asn1.x509.X500Name({str:'/C=JP/O=b/CN=a@a.jp',rule:'prn'});
equal(o.getEncodedHex(),
"302a310b3009060355040613024a50310a3008060355040a130162310f300d060355040316066140612e6a70",
"constructor /C=JP/O=b/CN=a@a.jp rule=prn");

o = new KJUR.asn1.x509.X500Name({str:'/C=JP/O=b/CN=a@a.jp'});
equal(o.getEncodedHex(),
"302a310b3009060355040613024a50310a3008060355040a0c0162310f300d060355040316066140612e6a70",
"constructor /C=JP/O=b/CN=a@a.jp rule=default");

});

// == RDN class TEST 
test("RDN class test", function() {
var _RDN = KJUR.asn1.x509.RDN;

equal((new _RDN({array: [{type:'O',value:'aaa',ds:'utf8'}]})).getEncodedHex(),
"310c300a060355040a0c03616161",
"(1) new {array: [{type:'O',value:'aaa',ds:'utf8'}]} rule=utf8(default)");

equal((new _RDN({array: [{type:'O',value:'aaa'}],rule:'prn'})).getEncodedHex(),
"310c300a060355040a1303616161",
"(2) new {array: [{type:'O',value:'aaa'}],rule:'prn'} ***KNOWN ISSUE FIXED IN THE FUTURE***");

equal((new _RDN({array: [{type:'O',value:'aaa',ds:'utf8'},{type:'CN',value:'bob@example.com',ds:'ia5'}]})).getEncodedHex(),
"3124300a060355040a0c0361616130160603550403160f626f62406578616d706c652e636f6d",
"(3) new {array: [{type:'O',value:'aaa',ds:'utf8'},{type:'CN',value:'bob@example.com',ds:'ia5'}]} rule=utf8(default) multi-valued-rdn");

equal((new _RDN({str:'O=aaa'})).getEncodedHex(),
"310c300a060355040a0c03616161",
"new {str:'O=aaa'} rule=utf8(default)");

equal((new _RDN({str:'O=aaa',rule:'prn'})).getEncodedHex(),
"310c300a060355040a1303616161",
"new {str:'O=aaa',rule:'prn'}");

equal((new _RDN({str:'O=aaa+CN=a@a.jp',rule:'prn'})).getEncodedHex(),
"311b300a060355040a1303616161300d060355040316066140612e6a70",
"new {str:'O=aaa+CN=a@a.jp',rule:'prn'}");

var o2 = new _RDN();
o2.addByString("O=aaa");
equal(o2.getEncodedHex(), "310c300a060355040a0c03616161", "addByString(O=aaa)");
});

// == AttributeTypeAndValue TEST
test("AttributeTypeAndValue class test", function() {
var _AttributeTypeAndValue = KJUR.asn1.x509.AttributeTypeAndValue;

equal(
(new _AttributeTypeAndValue({type:"O",value:"aaa",ds:"utf8"})).getEncodedHex(),
"300a060355040a0c03616161", "new ({type:O,value:aaa,ds:utf8})");

equal(
(new _AttributeTypeAndValue({type:"O",value:"aaa",ds:"prn"})).getEncodedHex(),
"300a060355040a1303616161", "new ({type:O,value:aaa,ds:prn})");

equal(
(new _AttributeTypeAndValue({'str':'O=aaa'})).getEncodedHex(),
"300a060355040a0c03616161", "new {'str':'O=aaa'} utf8");

equal(
(new _AttributeTypeAndValue({'str':'O=あ'})).getEncodedHex(),
"300a060355040a0c03e38182", "new {'str':'O=あ'} utf8");

var o0 = new _AttributeTypeAndValue();
o0.setByParam({type:"O",value:"aaa",ds:"utf8"});
equal(o0.getEncodedHex(), "300a060355040a0c03616161", "setByParam");

var o1 = new _AttributeTypeAndValue();
o1.setByAttrTypeAndValueStr("O", "aaa");
equal(o1.getEncodedHex(), "300a060355040a0c03616161", "setByAttrTypeAndValueStr O aaa");

var o2 = new _AttributeTypeAndValue();
o2.setByString("O=aaa");
equal(o2.getEncodedHex(), "300a060355040a0c03616161", "setByString(O=aaa)");

var o5 = new _AttributeTypeAndValue({str:'C=JP'});
equal(o5.getEncodedHex(), "3009060355040613024a50", "o5 C=JP(prn)");
equal(o5.sType, "C", "o5 sType=C");
equal(o5.sValue, "JP", "o5 sValue=JP");
equal(o5.dsType, "prn", "o5 dsType=prn");
equal(o5._getDsType(), "prn", "o5 getDsType=prn");
equal(o5.sRule, "utf8", "o5 sRule=utf8");

var o6 = new _AttributeTypeAndValue({'str':'CN=aa@aa.jp'});
equal(o6.getEncodedHex(), "300f0603550403160861614061612e6a70", "constructor CN=aa@aa.jp(ia5) rule=default");

var o7 = new _AttributeTypeAndValue({str:'O=aaa',rule:'prn'});
equal(o7.getEncodedHex(), "300a060355040a1303616161", "constructor str O=aaa(prn)");
equal(o7.sRule, "prn", "o7 sRule=prn");

var o8 = new _AttributeTypeAndValue({str:'CN=aa@aa.jp',rule:'prn'});
equal(o8.getEncodedHex(), "300f0603550403160861614061612e6a70", "constructor CN=aa@aa.jp(ia5) rule=prn");
equal(o8.sRule, "prn", "o8 sRule=prn");

});


// ===== END Name related class test ==============

test("Time class test", function() {
  expect(4);

  var o1 = new KJUR.asn1.x509.Time({'str':'130430235959Z'}); // UTC
  equal(o1.getEncodedHex(), "170d3133303433303233353935395a", "constructor default timestr");

  var o2 = new KJUR.asn1.x509.Time({'str':'20130430235959Z', 'type': 'gen'}); // Gen
  equal(o2.getEncodedHex(), "180f32303133303433303233353935395a", "constructor default timestr");

  var o3 = new KJUR.asn1.x509.Time({'str':'20130430235959Z'}); // Gen
  equal(o3.getEncodedHex(), "180f32303133303433303233353935395a", "constructor default timestr (auto gen)");

  var o4 = new KJUR.asn1.x509.Time(); // auto UTC
  equal(o4.getEncodedHex().substr(0, 4), "170d", "constructor default timestr (empty)=170d...");
});

test("SubjectPublicKeyInfo class test", function() {
  var rsaKey = new RSAKey();
  rsaKey.setPublic('e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a', '10001');
  var o1 = new KJUR.asn1.x509.SubjectPublicKeyInfo(rsaKey);
  equal(o1.getEncodedHex(), "3057300d06092a864886f70d01010105000346003043023c00e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a0203010001", "constructor default rsaKey");

  var pubpem2 =
    "-----BEGIN PUBLIC KEY-----\n" +
    "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOtpGHibL8Ue+MXPPufkcrNES40rCT5L\n" +
    "RIU9MjTZ8/7owG5bAsiFA9Xxh3uZK1T5QA64jNJVbp2ojHAtNyWPuwsCAwEAAQ==" +
    "-----END PUBLIC KEY-----\n" 
  var pubobj2 = KEYUTIL.getKey(pubpem2);
  var o2 = new KJUR.asn1.x509.SubjectPublicKeyInfo();
  o2.setPubKey(pubobj2);
  equal(o2.getEncodedHex(), "305c300d06092a864886f70d0101010500034b003048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001", "pubpem2");
});

// ===== END Basic Field related class test ==============

// BasicConstraints
test("BasicConstraints class test", function() {
  expect(6);
  var o1 = new KJUR.asn1.x509.BasicConstraints({});
  equal(o1.getExtnValueHex(), "3000", "constructor cA=f getExtnValueHex");
  equal(o1.getEncodedHex(), "30090603551d1304023000", "constructor cA=f getEncodedHex");

  var o2 = new KJUR.asn1.x509.BasicConstraints({'cA':true});
  equal(o2.getExtnValueHex(), "30030101ff", "constructor cA=t getExtnValueHex");
  equal(o2.getEncodedHex(), "300c0603551d13040530030101ff", "constructor cA=t getEncodedHex");

  var o3 = new KJUR.asn1.x509.BasicConstraints({'cA':true, 'pathLen': 7});
  equal(o3.getExtnValueHex(), "30060101ff020107", "constructor cA=t pl=7 getExtnValueHex");
  equal(o3.getEncodedHex(), "300f0603551d13040830060101ff020107", "constructor cA=t pl=7 getEncodedHex");
});

// KeyUsage
test("KeyUsage class test", function() {
  var o;
  o = new KJUR.asn1.x509.KeyUsage({'bin':'11'});
  equal(o.getExtnValueHex(), "030206c0", "constructor bin 11 getExtnValueHex");
  equal(o.getEncodedHex(), "300b0603551d0f0404030206c0", "constructor bin 11 getEncodedHex");

  o = new KJUR.asn1.x509.KeyUsage({'bin':'11', 'critical': true});
  equal(o.getEncodedHex(), "300e0603551d0f0101ff0404030206c0", "constructor bin 11 critical getEncodedHex");

  o = new KJUR.asn1.x509.KeyUsage({'names': ['digitalSignature', 'nonRepudiation']});
  equal(o.getEncodedHex(), "300b0603551d0f0404030206c0", "constructor names [digitalSignature, nonRepudiation]");

  o = new KJUR.asn1.x509.KeyUsage({'bin':'000000011'});
  equal(o.getEncodedHex(), "300c0603551d0f04050303070180", "constructor bin 000000011");

  o = new KJUR.asn1.x509.KeyUsage({'names': ['encipherOnly', 'decipherOnly']});
  equal(o.getEncodedHex(), "300c0603551d0f04050303070180", "constructor names [encipherOnly, decipherOnly]");
});

// CRLDP
test("CRLDistributionPoints class test", function() {
var _GeneralNames = KJUR.asn1.x509.GeneralNames;
var _DistributionPointName = KJUR.asn1.x509.DistributionPointName;
var _DistributionPoint = KJUR.asn1.x509.DistributionPoint;
var _CRLDistributionPoints = KJUR.asn1.x509.CRLDistributionPoints;

var gn1 = new _GeneralNames([{'uri':'http://aaa.com/'}]);
var dpn1 = new _DistributionPointName(gn1);
var dp1 = new _DistributionPoint({'dpobj': dpn1});
equal(
(new _CRLDistributionPoints({'array': [dp1]})).getEncodedHex(),
"30200603551d1f041930173015a013a011860f687474703a2f2f6161612e636f6d2f",
"constructor array [dp] param http://aaa.com/");

equal(
(new _CRLDistributionPoints({'uri': 'http://aaa.com/'})).getEncodedHex(),
"30200603551d1f041930173015a013a011860f687474703a2f2f6161612e636f6d2f",
"constructor by uri param http://aaa.com/");

equal(
(new _CRLDistributionPoints({
  array: [{fulluri: "http://aaa.com/"}]
})).getEncodedHex(),
"30200603551d1f041930173015a013a011860f687474703a2f2f6161612e636f6d2f",
"constructor by array fulluri param http://aaa.com/");

equal(
(new _CRLDistributionPoints({
  array: [{dpname: {full: [{uri: "http://aaa.com/"}]}}]
})).getEncodedHex(),
"30200603551d1f041930173015a013a011860f687474703a2f2f6161612e636f6d2f",
"constructor by uarray dpname full uri param http://aaa.com/");

equal(
(new _CRLDistributionPoints({
  array: [{fulluri: "http://aaa.com/"}, {fulluri: "ldap://aaa.com/"}]
})).getEncodedHex(),
"30370603551d1f0430302e3015a013a011860f687474703a2f2f6161612e636f6d2f3015a013a011860f6c6461703a2f2f6161612e636f6d2f",
"constructor by array fulluri param two dp {http,ldap}://aaa.com/");

});

test("DistributionPoint class test", function() {
var _GeneralNames = KJUR.asn1.x509.GeneralNames;
var _DistributionPointName = KJUR.asn1.x509.DistributionPointName;
var _DistributionPoint = KJUR.asn1.x509.DistributionPoint;

var o1aa = new _GeneralNames([{'uri':'http://aaa.com/'}]);
var o1a = new _DistributionPointName(o1aa);
var o1 = new _DistributionPoint({'dpobj': o1a});
equal(
o1.getEncodedHex(),
"3015a013a011860f687474703a2f2f6161612e636f6d2f",
"constructor by dpobj parameter http://aaa.com/");

equal(
(new _DistributionPoint({dpname: {full: [{uri: "http://aaa.com/"}]}})).getEncodedHex(),
"3015a013a011860f687474703a2f2f6161612e636f6d2f",
"constructor by dpname parameter http://aaa.com/");

equal(
(new _DistributionPoint({fulluri: "http://aaa.com/"})).getEncodedHex(),
"3015a013a011860f687474703a2f2f6161612e636f6d2f",
"constructor by fulluri parameter http://aaa.com/");

});

test("DistributionPointName class test", function() {
var _GeneralNames = KJUR.asn1.x509.GeneralNames;
var _DistributionPointName = KJUR.asn1.x509.DistributionPointName;
var o1a = new _GeneralNames([{'uri':'http://aaa.com/'}]);
var o1 = new _DistributionPointName(o1a);
equal(
o1.getEncodedHex(),
"a011860f687474703a2f2f6161612e636f6d2f",
"constructor by GeneralNames object");

equal(
(new _DistributionPointName({full: [{'uri':'http://aaa.com/'}]})).getEncodedHex(),
"a011860f687474703a2f2f6161612e636f6d2f",
"constructor by JSON parameter");
});

// ExtKeyUsage
test("ExtKeyUsage class test", function() {
  expect(1);

 var eku1 = 
 	new KJUR.asn1.x509.ExtKeyUsage({'array':
	                                [{'oid': '2.5.29.37.0'},  // anyExtendedKeyUsage
					 {'name': 'clientAuth'}]});
  equal(eku1.getEncodedHex(), "30190603551d25041230100604551d250006082b06010505070302", "constructor array");
});

// AuthorityKeyIdentifier
test("AuthorityKeyIdentifier class test (kid=hex)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'kid': {'hex': '89ab'}});
equal(o1.getExtnValueHex(), "3004800289ab", "kid value");
equal(o1.getEncodedHex(), "300d0603551d2304063004800289ab", "ext hex");
});

// aaa3.sbj.cer.pem
test("AuthorityKeyIdentifier class test (kid=CERTPEM)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'kid': CERTEE1});
equal(o1.getExtnValueHex(), "3016801481c33bde1624640e5be7d9a545c44bd488bce204", "extnValue=" + o1.getExtnValueHex());
equal(o1.getEncodedHex(), "301f0603551d2304183016801481c33bde1624640e5be7d9a545c44bd488bce204", "hTLV=" + o1.getEncodedHex());
});

test("AuthorityKeyIdentifier class test (kid=PUBKEYOBJ)", function() {
var pub = KEYUTIL.getKey(PUBKEYRSA1);
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'kid': pub});
equal(o1.getExtnValueHex(), "30168014ae6c05a39313e2a2e7e2d71cd6c7f07fc86753a0", "extnValue=" + o1.getExtnValueHex());
equal(o1.getEncodedHex(), "301f0603551d23041830168014ae6c05a39313e2a2e7e2d71cd6c7f07fc86753a0", "hTLV=" + o1.getEncodedHex());
});

test("AuthorityKeyIdentifier class test (issuer=str)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'issuer': {'str': '/C=US/CN=a'}});
equal(o1.getExtnValueHex(), "301fa11da41b3019310b3009060355040613025553310a300806035504030c0161", "issuer name");
equal(o1.getEncodedHex(), "30280603551d230421301fa11da41b3019310b3009060355040613025553310a300806035504030c0161", "ext hex");
});

// aaa3.sbj.cer.pem
test("AuthorityKeyIdentifier class test (issuer=PEM)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({issuer: CERTEE1});
equal(o1.getExtnValueHex(), "3021a11fa41d301b310b3009060355040613025553310c300a060355040a0c03434131", "extnValue=" + o1.getExtnValueHex());
equal(o1.getEncodedHex(), "302a0603551d2304233021a11fa41d301b310b3009060355040613025553310c300a060355040a0c03434131", "hTLV=" + o1.getEncodedHex());
});

test("AuthorityKeyIdentifier class test (sn=hex)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'sn': {'hex': '1234'}});
equal(o1.getExtnValueHex(), "300482021234", "cert SN");
equal(o1.getEncodedHex(), "300d0603551d230406300482021234", "ext hex");
});

// aaa3.sbj.cer.pem
test("AuthorityKeyIdentifier class test (sn=PEM)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({sn: CERTEE1});
equal(o1.getExtnValueHex(), "3003820107", "extnValue=" + o1.getExtnValueHex());
equal(o1.getEncodedHex(), "300c0603551d2304053003820107", "hTLV=" + o1.getEncodedHex());
});

test("AuthorityKeyIdentifier class test (kid=hex,issuer=str,sn=hex)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'kid': {'hex': '89ab'},
                                                    'issuer': {'str': '/C=US/CN=a'},
                                                    'sn': {'hex': '1234'}});
equal(o1.getExtnValueHex(), "3027800289aba11da41b3019310b3009060355040613025553310a300806035504030c016182021234", "all");
equal(o1.getEncodedHex(), "30300603551d2304293027800289aba11da41b3019310b3009060355040613025553310a300806035504030c016182021234", "ext hex");
});

test("AuthorityKeyIdentifier class test (issuer=str,sn=hex)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({
  issuer: {str: '/C=JP/O=T1'},
  sn: {hex: '01'}
});
equal(o1.getEncodedHex(), "302c0603551d2304253023a11ea41c301a310b3009060355040613024a50310b3009060355040a0c025431820101", "hTLV=" + o1.getEncodedHex());
});

// aaa3.sbj.cer.pem
test("AuthorityKeyIdentifier class test (issuersn=PEM)", function() {
var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({issuersn: CERTEE1});
equal(o1.getExtnValueHex(), "3024a11fa41d301b310b3009060355040613025553310c300a060355040a0c03434131820107", "extnValue=" + o1.getExtnValueHex());
equal(o1.getEncodedHex(), "302d0603551d2304263024a11fa41d301b310b3009060355040613025553310c300a060355040a0c03434131820107", "hTLV=" + o1.getEncodedHex());
});

test("AuthorityKeyIdentifier class", function() {
var _AuthorityKeyIdentifier = KJUR.asn1.x509.AuthorityKeyIdentifier;

var o1 = new _AuthorityKeyIdentifier({kid: {hex: '89ab'}, critical: true});
equal(o1.getExtnValueHex(),
      "3004800289ab",
      "constructor kid,critical extnhex");
equal(o1.getEncodedHex(),
      "30100603551d230101ff04063004800289ab",
      "constructor kid,critical enchex");

equal(
(new _AuthorityKeyIdentifier({
  kid: {hex: "27e00502504b088259f76ece524799e2246e30eb"},
  issuer: {hex: "301a310b3009060355040613024a50310b3009060355040a0c025431"},
  sn: {hex: "01"},
  critical:true
})).getEncodedHex(),
"30450603551d230101ff043b3039801427e00502504b088259f76ece524799e2246e30eba11ea41c301a310b3009060355040613024a50310b3009060355040a0c025431820101",
"constructor with kid,issuer,sn,critical");
});

// SubjectKeyIdentifier
test("SubjectKeyIdentifier class test (kid=hex)", function() {
  var o1 = new KJUR.asn1.x509.SubjectKeyIdentifier({'kid': {'hex': '89ab'}});
  equal(o1 instanceof KJUR.asn1.x509.SubjectKeyIdentifier, true, "instance of");
  equal(o1.asn1KID instanceof KJUR.asn1.DEROctetString, true, "asn1KID instanceof OctetString");
  equal(o1.getExtnValueHex(), "040289ab", "kid value");
  equal(o1.getEncodedHex(), "300b0603551d0e0404040289ab", "ext hex");
});

test("SubjectKeyIdentifier class test (kid=hex,critical)", function() {
  var o1 = new KJUR.asn1.x509.SubjectKeyIdentifier({'kid': {'hex': '89ab'}, 'critical': true});
  equal(o1 instanceof KJUR.asn1.x509.SubjectKeyIdentifier, true, "instance of");
  equal(o1.getEncodedHex(), "300e0603551d0e0101ff0404040289ab", "ext hex");
});

// SubjectKeyIdentifier
test("SubjectKeyIdentifier class test (kid=PUBKEYOBJ)", function() {
  var pub = KEYUTIL.getKey(PUBKEYRSA1);
  var o1 = new KJUR.asn1.x509.SubjectKeyIdentifier({'kid': pub});

  equal(o1.getExtnValueHex(), "0414ae6c05a39313e2a2e7e2d71cd6c7f07fc86753a0", "extn=" + o1.getExtnValueHex());
  equal(o1.getEncodedHex(), "301d0603551d0e04160414ae6c05a39313e2a2e7e2d71cd6c7f07fc86753a0", "hTLV=" + o1.getEncodedHex());
});

test("SubjectKeyIdentifier class test (kid=CERTPEM)", function() {
  var o1 = new KJUR.asn1.x509.SubjectKeyIdentifier({'kid': CERTEE1});
  equal(o1.getExtnValueHex(), "041481c33bde1624640e5be7d9a545c44bd488bce204", "extn=" + o1.getExtnValueHex());
  equal(o1.getEncodedHex(), "301d0603551d0e0416041481c33bde1624640e5be7d9a545c44bd488bce204", "hTLV=" + o1.getEncodedHex());
});

// SubjectAltName
test("SubjectAltName", function() {
  var o1 = new KJUR.asn1.x509.SubjectAltName({
    critical: true,
    array: [{uri: 'http://a.com'}, {uri: 'http://b.com'}]
  });
  equal(o1.getExtnValueHex(), "301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "URIs critical");
  equal(o1.getEncodedHex(), "30280603551d110101ff041e301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "ext hex");
});

test("IssuerAltName", function() {
  var o1 = new KJUR.asn1.x509.IssuerAltName({
    critical: true,
    array: [{uri: 'http://a.com'}, {uri: 'http://b.com'}]
  });
  equal(o1.getExtnValueHex(), "301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "URIs critical");
  equal(o1.getEncodedHex(), "30280603551d120101ff041e301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "ext hex");
});

test("CertificatePolicies test", function() {
var _CertificatePolicies = KJUR.asn1.x509.CertificatePolicies;

equal(
(new _CertificatePolicies({
array: [
  { policyoid: "1.2.3.4.5",
    array: [
      { cps: "https://example.com/repository" },
      { unotice: {
        noticeref: {
          org: {type: "ia5", str: "Sample Org"},
          noticenum: [{int: 5}, {hex: "01af"}]
        },
        exptext: {type: "ia5", str: "Sample Policy"}
      }}
    ]
  },
  { policyoid: "1.2.3.4.6",
    array: [
      { cps: "https://example2.org/repository" },
      { unotice: {
        noticeref: {
          org: {type: "utf8", str: "Sample2 Org"},
          noticenum: [{int: 5}]
        },
        exptext: {type: "utf8", str: "Sample2 Policy"}
      }}
    ]
  }
],
critical: true
})).getEncodedHex(),
"3081e10603551d200101ff0481d63081d3306806042a0304053060302a06082b06010505070201161e68747470733a2f2f6578616d706c652e636f6d2f7265706f7369746f7279303206082b0601050507020230263015160a53616d706c65204f72673007020105020201af160d53616d706c6520506f6c696379306706042a030406305f302b06082b06010505070201161f68747470733a2f2f6578616d706c65322e6f72672f7265706f7369746f7279303006082b06010505070202302430120c0b53616d706c6532204f726730030201050c0e53616d706c653220506f6c696379",
"two policies 1.2.3.4.{5,6}");

equal(
(new _CertificatePolicies({
array: [
  { policyoid: "2.23.140.1.2.1" },
  { policyoid: "1.3.6.1.4.1.44947.1.1.1",
    array: [
      { cps: "https://cps.letsencrypt.org" },
      { unotice: {
        exptext: {type: "utf8", 
	          str: "This Certificate may only be relied upon by Relying Parties and only in accordance with the Certificate Policy found at https://letsencrypt.org/repository/"}
      }}
    ]
  }
]
})).getEncodedHex(),
"3081ff0603551d200481f73081f43008060667810c0102013081e7060b2b0601040182df130101013081d7302706082b06010505070201161b68747470733a2f2f6370732e6c657473656e63727970742e6f72673081ab06082b0601050507020230819e0c819b54686973204365727469666963617465206d6179206f6e6c792062652072656c6965642075706f6e2062792052656c79696e67205061727469657320616e64206f6e6c7920696e206163636f7264616e636520776974682074686520436572746966696361746520506f6c69637920666f756e642061742068747470733a2f2f6c657473656e63727970742e6f72672f7265706f7369746f72792f",
"lets encrypt");

});

test("PolicyInformation test", function() {
var _PolicyInformation = KJUR.asn1.x509.PolicyInformation;

equal(
(new _PolicyInformation({
  policyoid: "1.2.3.4.5",
  array: [
    { cps: "https://example.com/repository" },
    { unotice: {
      noticeref: {
        org: {type: "ia5", str: "Sample Org"},
        noticenum: [{int: 5}, {hex: "01af"}]
      },
      exptext: {type: "ia5", str: "Sample Policy"}
    }}
  ]
})).getEncodedHex(),
"306806042a0304053060302a06082b06010505070201161e68747470733a2f2f6578616d706c652e636f6d2f7265706f7369746f7279303206082b0601050507020230263015160a53616d706c65204f72673007020105020201af160d53616d706c6520506f6c696379",
"policyinformation 1.2.3.4.5 full"
);

var param2 = {
  policyoid: "anyPolicy"
};
equal(
(new _PolicyInformation(param2)).getEncodedHex(),
"30060604551d2000",
"anyPolicy hex");
equal(
ASN1HEX.dump((new _PolicyInformation(param2)).getEncodedHex()),
ASN1HEX.dump("30060604551d2000"),
"anyPolicy dump=" + ASN1HEX.dump("30060604551d2000"));

});

test("PolicyQualifierInfo test", function() {
var _PolicyQualifierInfo = KJUR.asn1.x509.PolicyQualifierInfo;

equal(
(new _PolicyQualifierInfo({
  cps: "https://example.org/"
})).getEncodedHex(),
"302006082b06010505070201161468747470733a2f2f6578616d706c652e6f72672f",
"cps");

equal(
(new _PolicyQualifierInfo({
  unotice: {
    noticeref: {
      org: {type: "ia5", str: "Sample Org"},
      noticenum: [{int: 5}, {hex: "01af"}]
    },
    exptext: {type: "ia5", str: "Sample Policy"}
  }
})).getEncodedHex(),
"303206082b0601050507020230263015160a53616d706c65204f72673007020105020201af160d53616d706c6520506f6c696379",
"unotice");

});

test("UserNotice test", function() {
var _UserNotice = KJUR.asn1.x509.UserNotice;
equal(
(new _UserNotice({
  noticeref: {
    org: {type: "ia5", str: "Sample Org"},
    noticenum: [{int: 5}, {hex: "01af"}]
  },
  exptext: {type: "ia5", str: "Sample Policy"}
})).getEncodedHex(),
"30263015160a53616d706c65204f72673007020105020201af160d53616d706c6520506f6c696379",
"usernotice");
});

test("NoticeReference test", function() {
var _NoticeReference = KJUR.asn1.x509.NoticeReference;

equal(
(new _NoticeReference({
  org: {type: "bmp", str: "Sample Org"},
  noticenum: [{int: 3}, {hex: "01af"}]
})).getEncodedHex(),
"30151e0a53616d706c65204f72673007020103020201af",
"both");

equal(
(new _NoticeReference({
  org: {type: "bmp", str: "Sample Org"}
})).getEncodedHex(),
"300c1e0a53616d706c65204f7267",
"org only");

equal(
(new _NoticeReference({
  noticenum: [{int: 3}, {hex: "01af"}]
})).getEncodedHex(),
"30093007020103020201af",
"noticenum only");
});

test("DisplayText test", function() {
var _DisplayText = KJUR.asn1.x509.DisplayText;
equal((new _DisplayText({str: 'aaa'})).getEncodedHex(),
      "0c03616161",
      "aaa(utf8 default)=0c03616161");
equal((new _DisplayText({type: 'utf8', str: 'aaa'})).getEncodedHex(),
      "0c03616161",
      "utf8,aaa=0c03616161");
equal((new _DisplayText({type: 'ia5', str: 'aaa'})).getEncodedHex(),
      "1603616161",
      "ia5str,aaa=1603616161");
equal((new _DisplayText({type: 'vis', str: 'aaa'})).getEncodedHex(),
      "1a03616161",
      "vis,aaa=1a03616161");
equal((new _DisplayText({type: 'bmp', str: 'aaa'})).getEncodedHex(),
      "1e03616161",
      "bmp,aaa=1e03616161");
});

test("AuthorityInfoAccess class test", function() {
equal(
(new KJUR.asn1.x509.AuthorityInfoAccess({
  array: [
    {ocsp: "http://ocsp.example.com"},
    {caissuer: "http://ocsp.example.com"}
  ]
})).getEncodedHex(),
"305806082b06010505070101044c304a302306082b060105050730018617687474703a2f2f6f6373702e6578616d706c652e636f6d302306082b060105050730028617687474703a2f2f6f6373702e6578616d706c652e636f6d",
"ocsp,caissuer"
);

equal(
(new KJUR.asn1.x509.AuthorityInfoAccess({
  array: [
    {ocsp: "http://ocsp.example.com"},
    {caissuer: "http://ocsp.example.com"}
  ],
  critical: true
})).getEncodedHex(),
"305b06082b060105050701010101ff044c304a302306082b060105050730018617687474703a2f2f6f6373702e6578616d706c652e636f6d302306082b060105050730028617687474703a2f2f6f6373702e6578616d706c652e636f6d",
"ocsp,caissuer,critical=true"
);

equal(
(new KJUR.asn1.x509.AuthorityInfoAccess({
  array: [
    {caissuer: "http://ocsp.example.com"},
    {ocsp: "http://ocsp.example.com"}
  ]
})).getEncodedHex(),
"305806082b06010505070101044c304a302306082b060105050730028617687474703a2f2f6f6373702e6578616d706c652e636f6d302306082b060105050730018617687474703a2f2f6f6373702e6578616d706c652e636f6d",
"caissuer,ocsp"
);

equal(
(new KJUR.asn1.x509.AuthorityInfoAccess({
  array: [
    {ocsp: "http://ocsp.example.com"}
  ]
})).getEncodedHex(),
"303306082b0601050507010104273025302306082b060105050730018617687474703a2f2f6f6373702e6578616d706c652e636f6d",
"ocsp"
);
});

test("OCSPNonce class test", function() {
var _OCSPNonce = KJUR.asn1.x509.OCSPNonce;
var hExpect = "301106092b06010505073001020404040212ab";
var params = {hex: "12ab"};
equal((new _OCSPNonce(params)).getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump((new _OCSPNonce(params)).getEncodedHex()), 
ASN1HEX.dump(hExpect), 
"dump");
});

test("OCSPNoCheck class test", function() {
var _OCSPNoCheck = KJUR.asn1.x509.OCSPNoCheck;
var hExpect = "300f06092b060105050730010504020500";
equal((new _OCSPNoCheck()).getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump((new _OCSPNoCheck()).getEncodedHex()), 
ASN1HEX.dump(hExpect), 
"dump");
});

test("PrivateExtension class test", function() {
var _PrivateExtension = KJUR.asn1.x509.PrivateExtension;
hExpect = "300c06032a030404051303616161";

var param1 = {extname: "1.2.3.4", extn: "1303616161"};
equal(
(new _PrivateExtension(param1)).getEncodedHex(),
hExpect,
"extn-hex");

var param2 = {extname: "1.2.3.4", extn: {prnstr:'aaa'}};
equal(
(new _PrivateExtension(param1)).getEncodedHex(),
hExpect,
"extn-json");

});

// ==== END OF X.509V3 EXTENSION TEST ===================

// ===== CRL related test ====================

test("CRL class test (by cakey)", function() {
var _CRL = KJUR.asn1.x509.CRL;
var hExpect = "30819c3048300d06092a864886f70d01010505003019310b3009060355040613025553310a3008060355040a0c0161170d3133303530343233353935395a170d3133303630343233353935395a300d06092a864886f70d0101050500034100161f6e8b3cbe992aa4eece8894516a65d530543c6f23e83860cc391ae8289504cbe91f118fd20e2b96966182f695f9dce27b3e76f7d84beeab293cc3c9649740";
var prvKey = new RSAKey();
prvKey.readPKCS5PrvKeyHex("3082013a020100024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001024078bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d022100fe9bd450866b3255614fde976a76ac0b1d5830dda64f5359b946d8512bc1239f022100e9ab680f5f05dbb0f4311b0e6f4368f4874a1238979d8bc600c35c6f20707c07022100d549cb698dc17d4fe30e5a84f3ade860033c1eeb7f67d286465c9fd817d45b3702201849b4bb44493b989d092da2c675df46eb790b83ce5e95d4b2e79b88017b2fa902207d261a96256d49b020cb1d587ecde127e093a4d2b34cdbff171f34125b5857a9");
var params = {
 sigalg: 'SHA1withRSA',
 issuer: {str: '/C=US/O=a'},
 thisupdate: '130504235959Z',
 nextupdate: '130604235959Z',
 cakey: prvKey
};

var crl1 = new _CRL(params);
equal(crl1.getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump(crl1.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");
});

test("CRL class test 2 (by sighex)", function() {
var _CRL = KJUR.asn1.x509.CRL;
var hExpect = "3063304b020101300d06092a864886f70d01010b05003019310b3009060355040613025553310a3008060355040a0c0161170d3133303530343233353935395a170d3133303630343233353935395a300d06092a864886f70d01010b05000305001234abcd";
var params = {
 version: 2,
 sigalg: 'SHA256withRSA',
 issuer: {str: '/C=US/O=a'},
 thisupdate: '130504235959Z',
 nextupdate: '130604235959Z',
 sighex: "1234abcd"
};
var crl1 = new _CRL(params);
equal(crl1.getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump(crl1.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");
});

test("TBSCertList class test", function() {
var _TBSCertList = KJUR.asn1.x509.TBSCertList;
var hExpect = "3081b3020101300d06092a864886f70d01010b0500301a310b3009060355040613024a50310b3009060355040a13025431170d3230303832313233353935395a170d3230303832383233353935395a30463021020212ab170d3230303430313233353935395a300c300a0603551d1504030a01013021020212bc170d3230303430353233353935395a300c300a0603551d1504030a0102a01d301b300a0603551d140403020108300d0603551d2304063004800212ab";
var params = {
 version: 2, // OPTION
 sigalg: "SHA256withRSA",
 issuer: {array: [[{type:'C',value:'JP',ds:'prn'}],
                  [{type:'O',value:'T1',ds:'prn'}]]},
 thisupdate: "200821235959Z",
 nextupdate: "200828235959Z", // OPTION
 revcert: [
  {sn: {hex: "12ab"}, date: "200401235959Z", ext: [{extname: "cRLReason", code:1}]},
  {sn: {hex: "12bc"}, date: "200405235959Z", ext: [{extname: "cRLReason", code:2}]}
 ],
 ext: [
  {extname: "cRLNumber", num: {'int': 8}},
  {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}}
 ]
};
equal(
(new _TBSCertList(params)).getEncodedHex(),
hExpect,
"hex");
equal(
ASN1HEX.dump((new _TBSCertList(params)).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");
});

test("CRLNumber extension test", function() {
var hExpect = "300a0603551d140403020107";
var _CRLNumber = KJUR.asn1.x509.CRLNumber;
equal((new _CRLNumber({num: {'int': 7}})).getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump((new _CRLNumber({num: {'int': 7}})).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");
});

test("CRLReason extension test", function() {
var hExpect = "300a0603551d1504030a0102";
var param = {code: 2};
var _CRLReason = KJUR.asn1.x509.CRLReason;
equal((new _CRLReason(param)).getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump((new _CRLReason(param)).getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");
});

test("OID class test", function() {
  var o = KJUR.asn1.x509.OID;
  equal(o.atype2obj('C').getEncodedHex(), "0603550406", "C");
  equal(o.name2obj('SHA1withRSA').getEncodedHex(), 
         "06092a864886f70d010105", "name2obj SHA1withRSA");
  equal(o.name2oid('basicConstraints'), '2.5.29.19', "name2oid basicConstraints");
  equal(o.name2oid('UNKNOWNOIDNAME'), '', "name2oid unknown name");
  equal(o.oid2name('2.5.29.19'), 'basicConstraints', "oid2name basicConstraints");
  equal(o.oid2name('0.0.0.0'), '', "oid2name unknown oid");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="index.html">TEST INDEX</a> |
<a href="qunit-do-x509-ext.html">x509-ext</a> |
<a href="qunit-do-x509-hex2dn.html">x509-hex2dn</a> |
<a href="qunit-do-asn1x509.html">asn1x509</a> |
<a href="qunit-do-asn1x509-newcrt.html">asn1x509-newcrt</a> |
<a href="qunit-do-asn1x509-multirdn.html">asn1x509-multirdn</a> |
<a href="qunit-do-asn1x509-tbscert.html">asn1x509-tbscert</a> |
<a href="qunit-do-asn1csr.html">asn1csr</a> |
</body>
</html>
